<?php
header ( "Cache-Control: no-store,no-cache, must-revalidate" );
header ( "Content-Type: text/html; charset=utf-8" );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Anmeldung</title>
<link href="design/style.css" rel="stylesheet" type="text/css" />
<script>
	function check()
	{
		var pseudo = document.getElementById('pseudo').value;
		var passwort = document.getElementById('passwort').value;
		if(passwort == "" || pseudo == ""){
			alert("Veuillez remplir tous les champs!");
			return false;
		}
		else
			return true;
	}
</script>
</head>

<body>
<?php
require_once $_SERVER ['DOCUMENT_ROOT'] . "/bib/class/php/mysql_class.php";
if (isset ( $_POST ['validieren'] ) && (! empty ( $_POST ['validieren'] ))) {
 	$mysql_bib = new mysql_class ( 'vksm.net.mysql', 'vksm_net', 'egDYxATy', 'vksm_net' );
//	$mysql_bib = new mysql_class ( 'localhost', 'root', '', 'regi' );
	
	$pseudo = $_POST ['pseudo'];
	$passwort = $_POST ['passwort'];
	
	$result = $mysql_bib->query ( "SELECT nachname, vorname FROM user WHERE pseudo = '$pseudo'" );
	
	$nachname = "";
	$vorname = "";
	foreach ( $result as $req ) {
		$nachname = $req ['nachname'];
		$vorname = $req ['vorname'];
	}
	
	$salt = $nachname . '.' . $vorname;
	
	$hashed_pwd_salt = crypt ( $passwort, $salt );
	
	$result = $mysql_bib->query ( "SELECT nachname, vorname FROM user WHERE pseudo = '$pseudo' AND passwort = '$hashed_pwd_salt' " );
	
	if (count ( $result ) == 0)
		// echo "<script language='javascript'>alert('Mitglied nicht identifiziert');location = 'index.php';</script>";
		echo '<FONT COLOR = RED>' . "Pseudo oder Passwort ungültig! Bitte versuchen Sie es erneut." . '</FONT>';
	else {
		$mydate = Date ( "d.m.Y" );
		session_start ();
		$request = $mysql_bib->query ( "SELECT id FROM user WHERE pseudo = '$pseudo' AND passwort = '$hashed_pwd_salt' " );
		
		foreach ( $request as $elt ) {
			$id = $elt ["id"];
		}
		
		$update = array (
				"lastRegistration" => $mydate 
		);
		$mysql_bib->update ( 'user', $update, "id = " . $id );
		
		$_SESSION ['login'] = $pseudo;
		echo "<script language='javascript'>window.location = 'gallery.php';</script>";
	}
	mysql_close ();
}
?>
<form style="width: 300px" method="post" action="index.php"
		onSubmit="return check()">
		<fieldset>
			<legend>Registrierung</legend>
			<table cellpadding="5" width="300px">
				<tbody>
					<tr>
						<td>Pseudo:</td>
						<td align="right"><input type="text" id="pseudo" name="pseudo"></td>
					</tr>

					<tr>
						<td>Mot de passe:</td>
						<td align="right"><input type="password" name="passwort"
							id="passwort"></td>
					</tr>

					<tr align="center">

						<td></td>
						<td align="right"><input type="submit" onClick="check()"
							name="validieren" id="validieren" value="validieren"></td>
					</tr>

					<tr>
						<td style="text-align: left"><span><a href="registrierung.php">
									Registrierung </a></span></td>
						<td style="text-align: right"><span><a
								href="http://www.vksm.net/de/aktivitaeten/tanz"> Zur Webseite des VKSM e.V.</a></span></td>
					</tr>
				</tbody>
			</table>

		</fieldset>
		Passwort Vergessen? Schicken Sie bitte den Administratoren eine <a
			href="mailto:admin@vksm.net">Email</a>.
	</form>
</body>
</html>
